/* 
*  Copyright (C) 2009-2010 WCG Project
*
*  This program is free software; you can redistribute it and/or modify it
*  under the terms of the GNU General Public License as published by the
*  Free Software Foundation; either version 2 of the License, or (at
*  your option) any later version.
*
*  This program is distributed in the hope that it will be useful, but
*  WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
*  General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software Foundation,
*  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*  In addition, as a special exception, the author gives permission to
*  link the code of this program with the Half-Life Game Engine ("HL
*  Engine") and Modified Game Libraries ("MODs") developed by Valve,
*  L.L.C ("Valve"). You must obey the GNU General Public License in all
*  respects for all of the code used other than the HL Engine and MODs
*  from Valve. If you modify this file, you may extend this exception
*  to your version of the file, but you are not obligated to do so. If
*  you do not wish to do so, delete this exception statement from your
*  version.
*/



/*
*	Counter-Strike and Condition Zero only functions
*/

const PRIMARY_WEAPONS_BITMASK = (1<<CSW_SCOUT)|(1<<CSW_XM1014)|(1<<CSW_MAC10)|(1<<CSW_AUG)|(1<<CSW_UMP45)|(1<<CSW_SG550)|(1<<CSW_GALIL)|(1<<CSW_FAMAS)|(1<<CSW_AWP)|(1<<CSW_MP5NAVY)|(1<<CSW_M249)|(1<<CSW_M3)|(1<<CSW_M4A1)|(1<<CSW_TMP)|(1<<CSW_G3SG1)|(1<<CSW_SG552)|(1<<CSW_AK47)|(1<<CSW_P90)
const SECONDARY_WEAPONS_BITMASK = (1<<CSW_P228)|(1<<CSW_ELITE)|(1<<CSW_FIVESEVEN)|(1<<CSW_USP)|(1<<CSW_GLOCK18)|(1<<CSW_DEAGLE)


// Counter-Strike/Condition Zero Skins
new const SKIN_CT[5][] 			= { "sas", "gsg9", "urban", "gign", "spetsnaz" }
new const SKIN_T[5][]			= { "arctic", "leet", "guerilla", "terror", "militia" }

new const Float:CS_SPEED_VIP	= 227.0

new const Float:CS_WEAPON_SPEED[31] =
{
	0.0,
	250.0,      // CSW_P228
	0.0,
	260.0,      // CSW_SCOUT
	250.0,      // CSW_HEGRENADE
	240.0,      // CSW_XM1014
	250.0,      // CSW_C4
	250.0,      // CSW_MAC10
	240.0,      // CSW_AUG
	250.0,      // CSW_SMOKEGRENADE
	250.0,      // CSW_ELITE
	250.0,      // CSW_FIVESEVEN
	250.0,      // CSW_UMP45
	210.0,      // CSW_SG550
	240.0,      // CSW_GALI
	240.0,      // CSW_FAMAS
	250.0,      // CSW_USP
	250.0,      // CSW_GLOCK18
	210.0,      // CSW_AWP
	250.0,      // CSW_MP5NAVY
	220.0,      // CSW_M249
	230.0,      // CSW_M3
	230.0,      // CSW_M4A1
	250.0,      // CSW_TMP
	210.0,      // CSW_G3SG1
	250.0,      // CSW_FLASHBANG
	250.0,      // CSW_DEAGLE
	235.0,      // CSW_SG552
	221.0,      // CSW_AK47
	250.0,      // CSW_KNIFE
	245.0       // CSW_P90
}

new const Float:CS_WEAPON_SPEED_ZOOM[31] =
{
	0.0,
	0.0,
	0.0,
	220.0,      // CSW_SCOUT
	0.0,
	0.0,
	0.0,
	0.0,
	240.0,      // CSW_AUG
	0.0,
	0.0,
	0.0,
	0.0,
	150.0,      // CSW_SG550
	0.0,
	0.0,
	0.0,
	0.0,
	150.0,      // CSW_AWP
	0.0,
	0.0,
	0.0,
	0.0,
	0.0,
	150.0,      // CSW_G3SG1
	0.0,
	0.0,
	235.0,      // CSW_SG552
	0.0,
	0.0,
	0.0
}



#define cs_is_primary_weapon(%1) ( (1<<%1) & PRIMARY_WEAPONS_BITMASK )
//stock cs_is_primary_weapon( iWeaponID )
//{
//	if( (1<<iWeaponID) & PRIMARY_WEAPONS_BITMASK )
//		return true
//
//	return false
//}


#define cs_is_secondary_weapon(%1) ( (1<<%1) & SECONDARY_WEAPONS_BITMASK )
//stock cs_is_secondary_weapon( iWeaponID )
//{
//	if( (1<<iWeaponID) & SECONDARY_WEAPONS_BITMASK )
//		return true
//
//	return false
//}


/*
public _CS_MinModelsLoop()
{
	static id = 1
	
	if( get_pcvar_num( CVAR_query_client ) )
	{
		if( is_user_connected(id) && !is_user_bot(id) && !is_amd64_server() )
			query_client_cvar( id, "cl_minmodels", "_CS_CheckMinModelsValue" )
		
		if( ++id > GameInfo[GI_MaxPlayers] )
			id = 1
	}

	new Float:delay = float( 1 + GameInfo[GI_MaxPlayers] - get_playersnum() )
	set_task( delay, "_CS_MinModelsLoop" )
}



public _CS_CheckMinModelsValue( id, const cvar[], const value[] )
{
	if( equali( cvar,"cl_minmodels" ) && strcmp( value, "0" ) )
	{
		client_cmd( id, "echo ^"======== Warcraft 3 Frozen Throne ========^"" );
		client_cmd( id, "echo ^"You were kicked because cl_minmodels is set to 1 on your client, please change this to 0.^"" );
		client_cmd( id, "echo ^"Type ^"cl_minmodels 0^" in your console and press enter to do this.^"" );
		client_cmd( id, "echo ^"=========================================^"" );
		server_cmd( "kick #%d ^"cl_minmodels 1 is not allowed on this server^"", get_user_userid( id ) );
	} 
}
*/

// Function is called when buytime is over
public _CS_BuyTimeOver()
{
	GameInfo[GI_BuyTime] = false
}



public CZ_BotHookHam( id )
{
	static bCZBotRegisterHam = false
	
	// Thx to Avalanche and GunGame of which this method is based off of
	if ( bCZBotRegisterHam || !is_user_connected(id) || GameInfo[GI_Mod] != GAME_CZERO )
		return

	// Recheck for safety.
	if ( (pev(id, pev_flags) & FL_FAKECLIENT) && get_pcvar_num(CVAR_bot_quota) > 0 )
	{
		// Post spawn fix for cz bots, since RegisterHam does not work for them
		RegisterHamFromEntity( Ham_TakeDamage, id, "EVENT_TakeDamage", 1 )
		RegisterHamFromEntity( Ham_Spawn, id, "EVENT_Spawn", 1)

		// Only needs to run once after ham is registed ignore.
		bCZBotRegisterHam = true
	}
}







//-------------------------------------------
// CS_ChangeSkin
//
// Function changes your skin for ITEM_MOLE and Chameleon
//-------------------------------------------
public CS_ChangeSkin( id, iFlag )
{
	switch( iFlag )
	{
		case SKIN_RESET:
		{
			if( PlayerInfo[id][PI_SkinSwitched] )
			{
				cs_reset_user_model( id )
				PlayerInfo[id][PI_SkinSwitched] = false
			}
		}
		
		case SKIN_SWITCH:
		{
			new iModelNum = random_num( 0, (GameInfo[GI_Mod] == GAME_CZERO) ? 4 : 3 )
			
			// Save which skin we're going to use
			if( PlayerInfo[id][PI_TeamID] == TEAM_CT )
				cs_set_user_model( id, SKIN_T[iModelNum] )
			else
				cs_set_user_model( id, SKIN_CT[iModelNum] )
	
			if( cs_get_user_defuse(id) )
				set_pev( id, pev_body, 0)
	
			PlayerInfo[id][PI_SkinSwitched] = true
		}
	}
}
